package nix.jsps;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import nix.commons.VerifyCode;

public class VerifyCodeServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		// 生成验证码图片
		VerifyCode vc = new VerifyCode();
		BufferedImage image = vc.getImage();
		// 保存验证码文本到session
		request.getSession().setAttribute("session_vcode", vc.getText());
		// 输出验证码图片至输出流
		VerifyCode.output(image, response.getOutputStream());
	}
}
